<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品评价</title>
    <link rel="stylesheet" href="{__CSS__}/element_ui.css"/>
    <link rel="stylesheet" href="{__CSS__}/style.css"/>
    <script src="{__JS__}/vue2.js"></script>
    <script src="{__JS__}/element_ui.js"></script>
    <script src="{__JS__}/axios.min.js"></script>
    <script src="{__JS__}/request.js"></script>
</head>
<body>
<div id="app">
    <div class="app-loading" v-if="pageLoading">
        <div class="app-loading__logo">
            <img src="{__IMG__}/logo.png"/>
        </div>
        <div class="app-loading__loader"></div>
        <div class="app-loading__title">{$title}</div>
    </div>
    <el-card class="box-card" v-else>
        <div slot="header" class="clearfix">
            <span>商品评价</span>
        </div>
        <div class="search-box">
            <el-button-group>
                <el-button :type="buttonType(0)" size="small" @click="checkTab(0)">全部</el-button>
                <el-button :type="buttonType(1)" size="small" @click="checkTab(1)">好评</el-button>
                <el-button :type="buttonType(2)" size="small" @click="checkTab(2)">中评</el-button>
                <el-button :type="buttonType(3)" size="small" @click="checkTab(3)">差评</el-button>
            </el-button-group>
            <el-form :inline="true" :model="searchForm" class="demo-form-inline" style="margin-top: 20px;">
                <el-form-item label="评论时间">
                    <el-date-picker
                            size="small"
                            v-model="searchForm.create_time"
                            type="daterange"
                            value-format="yyyy-MM-dd"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit" icon="el-icon-search" size="small">查询</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div style="width:100%;height:0;border-bottom:#E4E7ED 1px dashed;margin-bottom: 10px"></div>
        <el-table
                :data="tableData"
                :row-style="{ height: '57px'}"
                style="width: 100%;font-size: 12px">
            <el-table-column
                    prop="id"
                    label="ID"
                    width="75">
            </el-table-column>
            <el-table-column
                    prop="goods_name"
                    label="商品信息"
                    width="300px">
            </el-table-column>
            <el-table-column
                    prop="user_name"
                    label="评论人">
            </el-table-column>
            <el-table-column
                    prop="type"
                    label="评论类型">
            </el-table-column>
            <el-table-column
                    prop="desc_match"
                    label="描述符合度">
            </el-table-column>
            <el-table-column
                    prop="content"
                    label="评论内容"
                    width="300px">
            </el-table-column>
            <el-table-column
                    prop="create_time"
                    label="评论时间">
            </el-table-column>
            <el-table-column
                    label="操作"
                    fixed="right">
                <template slot-scope="scope">
                    <el-button @click="handleDel(scope.row)" type="text" size="small">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="page-div" style="margin-top: 20px">
            <el-pagination
                    background
                    layout="prev, pager, next"
                    :page-size="searchForm.limit"
                    @current-change="pageChangeHandle"
                    :total="page.total">
            </el-pagination>
        </div>
    </el-card>
</div>
<script>

    new Vue({
        el: '#app',
        data: function() {
            return {
                pageLoading: true,
                baseIndex: '/{:config("shop.backend_index")}/',
                searchForm: {
                    type: 0,
                    create_time: '',
                    page: 1,
                    limit: 10
                },
                page: {
                    total: 0
                },
                tableData: []
            }
        },
        mounted() {
            this.getList()
            this.pageLoading = false
        },
        methods: {
            async getList() {
                let res = await request.get(this.baseIndex + "appraise/index", this.searchForm)
                this.tableData = res.data.data
                this.page.total = res.data.total
            },
            // 搜索
            onSubmit() {
                this.searchForm.page = 1
                this.getList()
            },
            // 删除
            handleDel(item) {
                this.$confirm('确定删除该评论？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(async () => {
                    let res = await request.get(this.baseIndex + 'appraise/del', {id: item.id});
                    if (res.code == 0) {
                        this.$message.success(res.msg)
                        setTimeout(() => {
                            this.getList()
                        }, 500)
                    } else {
                        this.$message.error(res.msg)
                    }
                }).catch(() => {});
            },
            // 选择状态
            checkTab(type) {
                this.searchForm.type = type
                this.getList()
            },
            // 翻页
            pageChangeHandle(page) {
                this.searchForm.page = page
                this.getList()
            },
            // 选择样式
            buttonType(type) {
                if (this.searchForm.type == type) {
                    return 'primary'
                }
            }
        }
    })
</script>
<style>
    .el-form-item {
        margin-bottom: 10px !important;
    }
    .el-table__row td {
        height: 57px !important;
    }
    .primary {
        color: #FFF;
        background-color: #409EFF;
        border-color: #409EFF;
    }
</style>
</body>
</html>